class Podcast < ActiveRecord::Base

  has_attachment  :content_type => 'audio/mpeg', 
  :storage => :file_system, 
  :max_size => 50.megabytes

  validates_as_attachment

  acts_as_taggable
  acts_as_authored

  named_url :key => 'title', :url_column => 'url_slug'
  
  def full_filename(thumbnail = nil)
    file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s
    File.join(RAILS_ROOT, file_system_path, url_slug, thumbnail_name_for(thumbnail))
  end
  
  def embeded_player
    "<object type='application/x-shockwave-flash' data='/player.swf' id='audioplayer#{id}' height='24' width='290'>
    <param name='movie' value='/player.swf'>
    <param name='FlashVars' value='playerID=1&amp;soundFile=#{public_filename}'>
    <param name='quality' value='high'>
    <param name='menu' value='false'>
    <param name='wmode' value='transparent'>
    </object>"
  end

  def summary(length = 30, end_string = ' …')
      words = body.split()
      words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')
  end
  
end
